package com.example.demo.utils;
import com.example.demo.pojo.Recharge;
import com.example.demo.pojo.UtilityBill;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;

public class RechargePdfUtil {
    public ByteArrayOutputStream createPdf(Recharge recharge) throws DocumentException, IOException {
        // 创建一个 ByteArrayOutputStream 实例
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        // 创建一个 Document 实例
        Document document = new Document();
        PdfWriter.getInstance(document, baos);

        // 打开文档
        document.open();



        // 设置字体路径
        String fontPath = "E:\\JetBrains\\songti.ttf";

// 设置中文字体
        Font fontTitle = FontFactory.getFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
        Font fontChinese = FontFactory.getFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

        // 添加标题
        Paragraph title = new Paragraph("充值账单", fontTitle);
        title.setAlignment(Element.ALIGN_CENTER);
        document.add(title);

        // 添加充值账单内容
        document.add(new Paragraph("充值记录ID: " + recharge.getRecordid(), fontChinese));
        document.add(new Paragraph("充值时间: " + recharge.getRechargetime(), fontChinese));
        document.add(new Paragraph("充值金额: " + recharge.getAmount(), fontChinese));
        document.add(new Paragraph("充值后余额: " + recharge.getBalanceafter(), fontChinese));
        document.add(new Paragraph("支付方式: " + recharge.getPaymentmethod(), fontChinese));
        document.add(new Paragraph("用户ID: " + recharge.getUserid(), fontChinese));
        document.add(new Paragraph("用户姓名: " + recharge.getRealname(), fontChinese));

        // 关闭文档
        document.close();


        return baos;
    }
}
